import bisect   # 一会总结一下这个的作用

# 思路巧妙
def countSmaller(nums):
    sortList = []
    res = []

    for i in reversed(nums):    # nums倒叙
        index = bisect.bisect_left(sortList, i)
        res.append(index)
        sortList.insert(index, i)
    res.reverse()
    return res